package com.zg.shop.categorysecond;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.zg.shop.utils.PageHibernateCallback;

public class CategorySecondDao extends HibernateDaoSupport {

	public Integer findCount() {
		List<Long> list = this.getHibernateTemplate().find("select count(*) from CategorySecond");
		if (list.size() > 0) {
			return list.get(0).intValue();
		}
		return null;
	}

	public List<CategorySecond> findByPage(Integer begin, int cslimit) {
		String hql = "from CategorySecond";
		List<CategorySecond> categorySeconds = this.getHibernateTemplate()
				.execute(new PageHibernateCallback<CategorySecond>(hql, null, begin, cslimit));
		if (categorySeconds.size() > 0) {
			return categorySeconds;
		}
		return null;
	}

	public void save(CategorySecond categorySecond) {
		this.getHibernateTemplate().save(categorySecond);
	}

	public void delete(CategorySecond categorySecond) {
		this.getHibernateTemplate().delete(categorySecond);
	}

	public CategorySecond findByCsid(Integer csid) {
		CategorySecond categorySecond = (CategorySecond) this.getHibernateTemplate().get(CategorySecond.class, csid);
		if(categorySecond != null){
			return categorySecond;
		}else {
			return null;
		}
	}

	public void update(CategorySecond categorySecond) {
		this.getHibernateTemplate().update(categorySecond);
	}

	public List<CategorySecond> findAll() {
		return this.getHibernateTemplate().find("from CategorySecond");
	}

}
